<script setup lang="ts">
import { useQuestion } from "@/store/question";
import { storeToRefs } from "pinia";
import { UserControllerService, UserVO } from "../../../generated";
import { onMounted, ref } from "vue";
import userRole from "@/access/permissionEnum";
import SubmitPage from "@/components/question/SubmitPage.vue";
import WatchQuestion from "@/components/question/WatchQuestion.vue";
import { useRouter } from "vue-router";

const router = useRouter();
const question = useQuestion();
let { submit, questionId } = storeToRefs(question);

let size = ref(0.5);

let userInfo = ref({
  createTime: "",
  id: 12,
  userAvatar: "",
  userName: "",
  userProfile: "",
  userRole: userRole.NOT_LOGIN,
} as UserVO);

let pageroutes = ["/", "/users", "/submit", "/admin"];

onMounted(async () => {
  const userVoByIdUsingGet = await UserControllerService.getUserVoByIdUsingGet(
    submit.value.userId as number
  );
  if (userVoByIdUsingGet.code == 0) {
    userInfo.value = userVoByIdUsingGet.data as UserVO;
  }
  questionId.value = submit.value.questionId as number;
});

const gotoOtherPage = (value: number) => {
  router.push(pageroutes[value]);
};
</script>

<template>
  <div style="height: 100%">
    <a-radio-group
      class="topPage"
      @change="gotoOtherPage"
      type="button"
      size="large"
    >
      <a-radio :value="0">题库</a-radio>
      <a-radio :value="1">用户管理</a-radio>
      <a-radio :value="2">做题</a-radio>
      <a-radio :value="3">题目提交管理</a-radio>
    </a-radio-group>
    <a-split
      :style="{
        top: '5%',
        height: '95%',
        width: '100%',
        minWidth: '500px',
        backgroundColor: 'white',
        position: 'fixed',
        border: '1px solid var(--color-border)',
      }"
      v-model:size="size"
      min="80px"
    >
      <template #first>
        <a-typography-paragraph>
          <div class="divider-demo">
            <div class="flex-box">
              <div class="content">
                <a-typography-title :heading="4">提交者</a-typography-title>
              </div>
            </div>
            <a-divider class="half-divider" />
            <div class="flex-box">
              <img class="avatar" :src="userInfo.userAvatar" />
              <div class="content">
                <a-typography-title :heading="6"
                  >{{ userInfo.userName }}<br />
                  用户Id: {{ userInfo.id }}
                </a-typography-title>
              </div>
            </div>
            <a-divider class="half-divider" />
            <div>
              <a-typography-title :heading="6">个人简介:</a-typography-title>
              {{
                userInfo.userProfile
                  ? userInfo.userProfile
                  : "用户很懒,没有介绍.."
              }}
            </div>
          </div>
          <a-typography style="padding: 20px">
            <WatchQuestion />
          </a-typography>
        </a-typography-paragraph>
      </template>
      <template #second>
        <a-typography-paragraph>
          <div class="page">
            <SubmitPage />
          </div>
        </a-typography-paragraph>
      </template>
    </a-split>
  </div>
</template>

<style scoped>
.divider-demo {
  box-sizing: border-box;
  width: 100%;
  padding: 20px;
  border: 30px solid rgb(var(--gray-2));
}

.half-divider {
  left: 55px;
  width: calc(100% - 55px);
  min-width: auto;
  margin: 16px 0;
}

.flex-box {
  display: flex;
  align-items: center;
  justify-content: center;
}

.flex-box .avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin-right: 16px;
  color: var(--color-text-2);
  font-size: 16px;
  background-color: var(--color-fill-3);
  border-radius: 50%;
}

.flex-box .content {
  flex: 1;
  color: var(--color-text-2);
  font-size: 12px;
  line-height: 100px;
}

.page {
  background-color: white;
}

.topPage {
  background-color: white;
  position: fixed;
  top: 0;
}
</style>
